home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / DesktopSwitch / DesktopSwitch.c next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  15.7 KB  |  566 lines  |  [TEXT/KAHL]

  1. /* DesktopSwitch.c – Move files to and from the desktop folder using preconfigured sets.
  2.  
  3. to do:
  4.  
  5. Allow saving of sets to disk.
  6. Allow user customization of sets, hiding  prefs, etc.
  7. */
  8.  
  9. #include <Quickdraw.h>
  10. #include <Controls.h>
  11. #include <Dialogs.h>
  12. #include "DialogRoutines.h"
  13. #include "DesktopSwitch.h"
  14. #include "FileRoutines.h"
  15. #include "UIRoutines.h"
  16.  
  17. PrefsHandle prefs;
  18.  
  19.  
  20.  
  21. /*-----------------------------------PutAwayAllItemsInFolder()-----------------------------------*/
  22. //move everything in the source directory to the destination directory
  23. OSErr PutAwayAllItemsInFolder(short theVRefNum, long theDirID)
  24. {
  25.     CInfoPBRec     myPBRec;
  26.     OSErr        theErr;
  27.     FSSpec         theFile;
  28.     Str255         myName;
  29.     unsigned short flags;
  30.     OSType type,creator;
  31.     EventRecord theEvent;
  32.     
  33.     myPBRec.hFileInfo.ioNamePtr = (StringPtr) NewPtr (sizeof(Str255));
  34.     myPBRec.hFileInfo.ioFDirIndex = 1;
  35.     //Loop through all items in the directory
  36.     do {
  37.         myPBRec.hFileInfo.ioVRefNum =         theVRefNum;
  38.         myPBRec.hFileInfo.ioDirID =         theDirID;
  39.         myPBRec.hFileInfo.ioCompletion =     NULL;
  40.         theErr = PBGetCatInfo (&myPBRec,false);
  41.         if (theErr == noErr){    
  42.             theErr = FSMakeFSSpec (theVRefNum,theDirID,
  43.                 myPBRec.hFileInfo.ioNamePtr,&theFile);  //Create FSSpec to the item
  44.             if (theErr == noErr) {
  45.                 flags = myPBRec.hFileInfo.ioFlFndrInfo.fdFlags;
  46.                 type = myPBRec.hFileInfo.ioFlFndrInfo.fdType;
  47.                 creator = myPBRec.hFileInfo.ioFlFndrInfo.fdCreator;
  48.         //only move unlocked, non-invisible files who aren't DesktopSwitch files
  49.                 if (!(flags & fInvisible) && !(flags & fNameLocked) && 
  50.                     !(creator == myCreator)) {
  51.                     if ((**prefs).PutAway){
  52.                         theErr = PutAwayItem(theFile);
  53.                         if (theErr) {
  54.                             //advance to the next file, reset the error
  55.                             myPBRec.hFileInfo.ioFDirIndex++;
  56.                             theErr = noErr;
  57.                             DebugStr ("\pCouldn't move file.");
  58.                         }
  59.                     }
  60.                     if ((**prefs).MakeInvis) {
  61.                         MakeInvisible(theFile);
  62.                         myPBRec.hFileInfo.ioFDirIndex++;
  63.                         theErr = noErr;
  64.                     }
  65.                 }
  66.                 else
  67.                     myPBRec.hFileInfo.ioFDirIndex++;
  68.             }
  69.             else 
  70.                 DebugStr ("\pFailed to create FSSpec to folder item.");
  71.         }
  72.         else 
  73.             if (theErr != fnfErr) DebugStr ("\pPBGetCatInfo failed.");
  74.     } while (theErr == noErr);
  75.     DisposPtr((Ptr)myPBRec.hFileInfo.ioNamePtr);
  76.     //Dont consided fnfErr a real error since it only indicates that we have looped
  77.     //through all items
  78.     if (theErr == fnfErr) 
  79.         return noErr;
  80.     else
  81.         return theErr;
  82. }
  83.  
  84. OSErr PutAwayItem (FSSpec theItem)
  85. {
  86.     FXInfo myFXInfo;
  87.     long awayDir;
  88.     Str31 name;
  89.     long dirID,errDirID;
  90.     FSSpec destSpec,junkFile,errFolder;
  91.     OSErr err;
  92.     Str255 tempStr;
  93.     
  94.     //2 for dirid means root dir
  95.     err = FSMakeFSSpec (theItem.vRefNum,2,(**prefs).folderName,&errFolder);
  96.     if (err)
  97.         FSpDirCreate (&errFolder,0,&errDirID);    
  98.     tempStr[0] = (**prefs).folderName[0] +2;
  99.     BlockMove (&(**prefs).folderName[1],&tempStr[2],(**prefs).folderName[0]);
  100.     tempStr[1] = ':';
  101.     tempStr[tempStr[0]] = ':';
  102.     BlockMove (&theItem.name[1],&tempStr[tempStr[0]+1],theItem.name[0]);
  103.     tempStr[0] += theItem.name[0];
  104.     FSMakeFSSpec (theItem.vRefNum,2,tempStr,&errFolder);
  105.     GetFinderInfo (theItem,NULL,&myFXInfo);
  106.     if (myFXInfo.fdPutAway == 0) { //nowhere to put it
  107.         if ((**prefs).MakeInvisWNF) {
  108.             MakeInvisible (theItem);
  109.             err = noErr;
  110.             goto done;
  111.         }
  112.         else
  113.             awayDir = errFolder.parID;
  114.     }
  115.     else
  116.         awayDir = myFXInfo.fdPutAway;
  117.     err = FSMakeFSSpec(theItem.vRefNum,awayDir,0,&destSpec);
  118.     if (err) {
  119.         if ((**prefs).MakeInvisWNF) {
  120.             MakeInvisible (theItem);
  121.             err = noErr;
  122.             goto done;
  123.         }
  124.         else {
  125.             awayDir = errFolder.parID;
  126.             FSMakeFSSpec (theItem.vRefNum,awayDir,0,&destSpec);
  127.         }
  128.     }
  129.     //this is strange – if we dont get an error here, that means a file by the same name already
  130.     //exists, so we'll just move this file to the root dir
  131.     if (! FSMakeFSSpec (theItem.vRefNum,awayDir,theItem.name,&junkFile))
  132.         if ((**prefs).MakeInvisWNF) {
  133.             MakeInvisible (theItem);
  134.             err = noErr;
  135.             goto done;
  136.         }
  137.         else {
  138.             awayDir = errFolder.parID;
  139.             FSMakeFSSpec (theItem.vRefNum,awayDir,0,&destSpec);
  140.         }
  141.     err = FSpCatMove(&theItem,&destSpec);
  142. done:
  143.     return err;
  144. }
  145.  
  146.  
  147. /*-----------------------------------HideItems()-----------------------------------*/
  148.  
  149. //put all items currently in the desktop folder away
  150. void HideItems()
  151. {    
  152.     short vref;
  153.     long ddirid,oldddirid;
  154.     OSErr err;
  155.     VCB * p;
  156.  
  157.     for (p = myVCBQHdr;p != NULL;p = (VCB *)p->qLink) {
  158.  
  159.         vref = p->vcbVRefNum;
  160.         err = FindFolder (vref,kDesktopFolderType,true,&vref,&ddirid);
  161.         if (err) goto done;
  162.         PutAwayAllItemsInFolder (vref,ddirid);
  163.         PutAwayAllItemsInFolder (vref,ddirid); //for some reason, we miss the last
  164.                                                         //item otherwise
  165.     }
  166.     
  167.     done:
  168.     //all done    
  169.     return;
  170. }
  171.  
  172. OSErr CreateDesktopFileList (FileListHandle *theDTFiles)
  173. {
  174.     short vref;
  175.     long ddirid;
  176.     FSSpec theFile;
  177.     CInfoPBRec     myPBRec;
  178.     unsigned short flags;
  179.     OSErr err;
  180.     
  181.     err = FindFolder (kOnSystemDisk,kDesktopFolderType,true,&vref,&ddirid);
  182.     if (err)
  183.         goto done;
  184.     *theDTFiles = (FileListHandle)NewHandle(sizeof(short)); //only a file count
  185.     (***theDTFiles).numFiles = 0;
  186.     myPBRec.hFileInfo.ioNamePtr = (StringPtr) NewPtr (sizeof(Str255));
  187.     myPBRec.hFileInfo.ioFDirIndex = 1;
  188.     //Loop through all items in the directory
  189.     do {
  190.         myPBRec.hFileInfo.ioVRefNum =         vref;
  191.         myPBRec.hFileInfo.ioDirID =         ddirid;
  192.         myPBRec.hFileInfo.ioCompletion =     NULL;
  193.         err = PBGetCatInfo (&myPBRec,false);
  194.         if (err == noErr){    
  195.             err = FSMakeFSSpec (vref,ddirid,
  196.                 myPBRec.hFileInfo.ioNamePtr,&theFile);  //Create FSSpec to the item
  197.             if (err == noErr) {
  198.                 flags = myPBRec.hFileInfo.ioFlFndrInfo.fdFlags;
  199.         //only include non-invisible files
  200.                 if (!(flags & fInvisible)){
  201.                     SetHandleSize((Handle)*theDTFiles,
  202.                                 GetHandleSize((Handle)*theDTFiles) + sizeof(Handle));
  203.                     if (MemError()) DebugStr ("\pCouldn't upsize DT file handle.");
  204.                     (***theDTFiles).numFiles++;
  205.                     err = NewAlias (NULL,
  206.                             &theFile,
  207.                             &(***theDTFiles).theFiles[(***theDTFiles).numFiles-1]);
  208.                     if (err) DebugStr ("\pNewAlias() failed.");
  209.                 }
  210.                 myPBRec.hFileInfo.ioFDirIndex++;
  211.             }
  212.             else 
  213.                 DebugStr ("\pFailed to create FSSpec to folder item.");
  214.         }
  215.         else 
  216.             if (err != fnfErr) DebugStr ("\pPBGetCatInfo failed.");
  217.     } while (err == noErr);
  218.     DisposPtr((Ptr)myPBRec.hFileInfo.ioNamePtr);
  219.     //Dont consided fnfErr a real error since it only indicates that we have looped
  220.     //through all items
  221. done:
  222.     if (err == fnfErr) 
  223.         return noErr;
  224.     else
  225.         return err;
  226.  
  227. }
  228.  
  229.  
  230. OSErr SaveDesktopFile (FSSpec theFile)
  231. {
  232.     FileListHandle theFileList;
  233.     FileListRsrcHandle fListRsrcHndl;
  234.     short rnum,newid,i;
  235.     Handle h;
  236.     FSSpec theSpec;
  237.     Boolean changed;
  238.     FInfo myFInfo;
  239.     
  240.     CreateDesktopFileList (&theFileList);
  241.     rnum = FSpOpenResFile(&theFile,fsRdWrPerm);
  242.     if (rnum <= 0) {
  243.         DebugStr ("\pFailed to open file.");
  244.         goto done;
  245.     }
  246.     fListRsrcHndl = (FileListRsrcHandle)NewHandle(sizeof(MyFInfoStruct) * ((**theFileList).numFiles) + sizeof(short));
  247.     if (!fListRsrcHndl) goto done;
  248.     (**fListRsrcHndl).numFiles = (**theFileList).numFiles;
  249.     for (i=0;i<(**theFileList).numFiles;i++){
  250.         newid = Unique1ID ('alis');
  251.         if (ResolveAlias(NULL,
  252.                         (**theFileList).theFiles[i],
  253.                         &theSpec,
  254.                         &changed)) continue;
  255.         GetFinderInfo (theSpec,&myFInfo,NULL);
  256.         (**fListRsrcHndl).fileList[i].filePos = myFInfo.fdLocation;
  257.         (**fListRsrcHndl).fileList[i].aliasID = newid;
  258.         h = (Handle)(**theFileList).theFiles[i];
  259.         AddResource (h,'alis',newid,"\p");
  260.         WriteResource (h);
  261.         DetachResource (h);
  262.         DisposHandle (h);
  263.     }
  264.     AddResource ((Handle)fListRsrcHndl,'flst',128,"\p");
  265.     WriteResource ((Handle)fListRsrcHndl);
  266.     ReleaseResource ((Handle)fListRsrcHndl);
  267.     DisposHandle ((Handle)theFileList);
  268.     done:
  269.         CloseResFile (rnum);
  270.         return ResError();
  271. }
  272.  
  273. //load a desktop file from disk, remove old files, move new ones in
  274. OSErr LoadDesktopFile (FSSpec theFile)
  275. {
  276.     FileListRsrcHandle dTopFiles;
  277.     short i;
  278.     FSSpec theSpec;
  279.     Boolean changed;
  280.     OSErr err;
  281.     short rnum;
  282.     Handle h;
  283.     FInfo myFInfo;
  284.     FXInfo myFXInfo;
  285.     EventRecord myEvt;
  286.     
  287.     //make everything else go away
  288.     HideItems();
  289.     WNEDelay (30);
  290.     //first, load according to desktop file resource
  291.     rnum = FSpOpenResFile (&theFile,fsRdWrPerm);
  292.     dTopFiles = (FileListRsrcHandle)GetResource ('flst',128);
  293.     if (!dTopFiles) goto done;
  294.     for (i=0;i<(**dTopFiles).numFiles;i++) {
  295.         h = GetResource('alis',(**dTopFiles).fileList[i].aliasID);
  296.         DetachResource (h);
  297.         if (ResolveAlias(NULL,
  298.                         (AliasHandle)h,
  299.                         &theSpec,
  300.                         &changed)) continue;
  301.         DisposHandle (h);
  302.         GetFinderInfo (theSpec,&myFInfo,&myFXInfo);
  303.         myFInfo.fdLocation = (**dTopFiles).fileList[i].filePos;
  304.         myFXInfo.fdPutAway = theSpec.parID;
  305.         SetFinderInfo (theSpec,&myFInfo,&myFXInfo);
  306.         MoveFileToDesktop(theSpec);
  307.     }
  308.     ReleaseResource ((Handle)dTopFiles);
  309.     CloseResFile (rnum);
  310.     done:
  311.         return err;
  312. }
  313.  
  314.  
  315.  
  316. OSErr CreateDTFileSet(void)
  317. {
  318.     StandardFileReply theReply;
  319.     OSErr err;
  320.     
  321.     StandardPutFile ("\pName of new desktop set:","\pDesktopSet",&theReply);
  322.     if (theReply.sfGood) {
  323.         if (theReply.sfReplacing)
  324.             FSpDelete(&theReply.sfFile);
  325.         FSpCreateResFile (&theReply.sfFile,'DTSW','dset',theReply.sfScript);
  326.         if (! ResError()) {
  327.             SaveDesktopFile (theReply.sfFile);
  328.         }
  329.         else
  330.             DebugStr ("\pFailed to save desktop file.");
  331.     }
  332.         
  333. }
  334.  
  335.  
  336. void UpdatePrefsDialogForSettings(DialogPtr theDialog)
  337. {
  338.     Rect iRect;
  339.     Handle iHandle;
  340.     short iType;
  341.  
  342.     if ((**prefs).PutAway){
  343.         GetDItem (theDialog,kPrefsDialog_MakeInvisible,&iType,&iHandle,&iRect);
  344.         SetCtlValue ((ControlHandle)iHandle,0);
  345.         GetDItem (theDialog,kPrefsDialog_PutAway,&iType,&iHandle,&iRect);
  346.         SetCtlValue ((ControlHandle)iHandle,1);
  347.         GetDItem (theDialog,kPrefsDialog_MoveToFolder,&iType,&iHandle,&iRect);
  348.         HiliteControl ((ControlHandle)iHandle,0);
  349.         GetDItem (theDialog,kPrefsDialog_MakeInvisWNF,&iType,&iHandle,&iRect);
  350.         HiliteControl ((ControlHandle)iHandle,0);        
  351.     } else
  352.     if ((**prefs).MakeInvis) {
  353.         GetDItem (theDialog,kPrefsDialog_PutAway,&iType,&iHandle,&iRect);
  354.         SetCtlValue ((ControlHandle)iHandle,0);
  355.         GetDItem (theDialog,kPrefsDialog_MakeInvisible,&iType,&iHandle,&iRect);
  356.         SetCtlValue ((ControlHandle)iHandle,1);
  357.         GetDItem (theDialog,kPrefsDialog_MoveToFolder,&iType,&iHandle,&iRect);
  358.         HiliteControl ((ControlHandle)iHandle,255);
  359.         GetDItem (theDialog,kPrefsDialog_FolderButton,&iType,&iHandle,&iRect);
  360.         HiliteControl ((ControlHandle)iHandle,255);
  361.         GetDItem (theDialog,kPrefsDialog_FolderText,&iType,&iHandle,&iRect);
  362.         //HiliteControl ((ControlHandle)iHandle,255);
  363.         SetIText (iHandle,"\p");
  364.         GetDItem (theDialog,kPrefsDialog_MakeInvisWNF,&iType,&iHandle,&iRect);
  365.         HiliteControl ((ControlHandle)iHandle,255);        
  366.     }
  367.     if ((**prefs).MoveToFolder && (**prefs).PutAway){
  368.         GetDItem (theDialog,kPrefsDialog_MoveToFolder,&iType,&iHandle,&iRect);
  369.         SetCtlValue ((ControlHandle)iHandle,1);
  370.         GetDItem (theDialog,kPrefsDialog_MakeInvisWNF,&iType,&iHandle,&iRect);
  371.         SetCtlValue ((ControlHandle)iHandle,0);
  372.         GetDItem (theDialog,kPrefsDialog_FolderButton,&iType,&iHandle,&iRect);
  373.         HiliteControl ((ControlHandle)iHandle,0);
  374.         GetDItem (theDialog,kPrefsDialog_FolderText,&iType,&iHandle,&iRect);
  375.         //HiliteControl ((ControlHandle)iHandle,0);
  376.         SetIText (iHandle,(**prefs).folderName);
  377.     }
  378.     else if ((**prefs).MakeInvisWNF && (**prefs).PutAway) {
  379.         GetDItem (theDialog,kPrefsDialog_MoveToFolder,&iType,&iHandle,&iRect);
  380.         SetCtlValue ((ControlHandle)iHandle,0);
  381.         GetDItem (theDialog,kPrefsDialog_MakeInvisWNF,&iType,&iHandle,&iRect);
  382.         SetCtlValue ((ControlHandle)iHandle,1);
  383.         GetDItem (theDialog,kPrefsDialog_FolderButton,&iType,&iHandle,&iRect);
  384.         HiliteControl ((ControlHandle)iHandle,255);
  385.         GetDItem (theDialog,kPrefsDialog_FolderText,&iType,&iHandle,&iRect);
  386.         //HiliteControl ((ControlHandle)iHandle,255);
  387.         SetIText (iHandle,"\p");
  388.     }
  389. }
  390.  
  391. void AskUserForFolder()
  392. {
  393.     DialogPtr theDialog;
  394.     short theItem;
  395.     short iType;
  396.     Rect iRect;
  397.     Handle iHand;
  398.     Str31 iText;
  399.     
  400.     theDialog = GetNewDialog (kGetFolderNameDialogID,NULL,(DialogPtr)-1L);
  401.     GetDItem (theDialog,kFolderNameDialog_Name,&iType,&iHand,&iRect);
  402.     SetIText (iHand,(**prefs).folderName);
  403.     do {
  404.         ModalDialog ((ProcPtr)StdFilterProc,&theItem);
  405.     } while (theItem != kFolderNameDialog_OK && theItem != kFolderNameDialog_Cancel);
  406.     if (theItem == kFolderNameDialog_OK) {
  407.         GetIText (iHand,iText);
  408.         BlockMove (iText,(**prefs).folderName,LENGTH(iText)+1);
  409.     }
  410.     DisposeDialog (theDialog);
  411. }
  412.  
  413. void ConfigurePrefs ()
  414. {
  415.     DialogPtr theDialog;
  416.     Rect iRect;
  417.     Handle iHandle;
  418.     short iType;
  419.     short theItem;
  420.     PrefsStruct oldPrefs;
  421.     
  422.     theDialog = GetNewDialog (kPrefsDialogID,NULL,(DialogPtr)-1L);
  423.     SetPort ((GrafPtr)theDialog);
  424.     GetDItem (theDialog,kPrefsDialog_UI1,&iType,&iHandle,&iRect);
  425.     FrameRect (&iRect);
  426.     GetDItem (theDialog,kPrefsDialog_UI2,&iType,&iHandle,&iRect);
  427.     FrameRect (&iRect);//this wont work
  428.     oldPrefs = (**prefs);
  429.     UpdatePrefsDialogForSettings(theDialog);
  430.     do {
  431.         ModalDialog((ProcPtr)StdFilterProc,&theItem);
  432.         switch (theItem) {
  433.             case kPrefsDialog_PutAway:
  434.                 if ((**prefs).PutAway)
  435.                     break;
  436.                 (**prefs).PutAway = true;
  437.                 (**prefs).MakeInvis = false;
  438.                 UpdatePrefsDialogForSettings(theDialog);
  439.                 break;
  440.             case kPrefsDialog_MakeInvisible:
  441.                 if ((**prefs).MakeInvis)
  442.                     break;
  443.                 (**prefs).MakeInvis = true;
  444.                 (**prefs).PutAway = false;
  445.                 UpdatePrefsDialogForSettings(theDialog);
  446.                 break;
  447.             case kPrefsDialog_MoveToFolder:
  448.                 if ((**prefs).MoveToFolder)
  449.                     break;
  450.                 (**prefs).MoveToFolder = true;
  451.                 (**prefs).MakeInvisWNF = false;
  452.                 UpdatePrefsDialogForSettings(theDialog);
  453.                 break;
  454.             case kPrefsDialog_MakeInvisWNF:
  455.                 if ((**prefs).MakeInvisWNF)
  456.                     break;
  457.                 (**prefs).MakeInvisWNF = true;
  458.                 (**prefs).MoveToFolder = false;
  459.                 UpdatePrefsDialogForSettings(theDialog);
  460.                 break;
  461.             case kPrefsDialog_FolderButton:
  462.                 AskUserForFolder();
  463.                 GetDItem (theDialog,kPrefsDialog_UI1,&iType,&iHandle,&iRect);
  464.                 FrameRect (&iRect);
  465.                 GetDItem (theDialog,kPrefsDialog_UI2,&iType,&iHandle,&iRect);
  466.                 FrameRect (&iRect);//this wont work
  467.                 DrawDialog (theDialog);
  468.                 UpdatePrefsDialogForSettings (theDialog);
  469.                 break;
  470.         }
  471.     } while (theItem != kPrefsDialog_OK && theItem != kPrefsDialog_Cancel);
  472.     if (theItem == kPrefsDialog_Cancel)
  473.         (**prefs) = oldPrefs;
  474.     else
  475.         SavePrefs();
  476.     DisposeDialog (theDialog);
  477.     
  478. }
  479.  
  480.  
  481. void LoadPrefs ()
  482. {
  483.     short vref,rnum;
  484.     long dirid;
  485.     FSSpec prefsFile;
  486.     OSErr err;
  487.     Str255 name;
  488.     
  489.     FindFolder(kOnSystemDisk,kPreferencesFolderType,true,&vref,&dirid);
  490.     err = FSMakeFSSpec (vref,dirid,"\pDesktopSwitch Prefs",&prefsFile);
  491.     if (err) {
  492.         FSpCreateResFile (&prefsFile,'DTSW','dspr',0);
  493.     }
  494.     rnum = FSpOpenResFile (&prefsFile,fsRdWrPerm);
  495.     if (rnum <= 0)
  496.         DebugStr ("\pCouldnt create prefs.");
  497.     prefs = (PrefsHandle)Get1Resource(kPrefsType,kPrefsID);
  498.     if (! prefs) {
  499.         prefs = (PrefsHandle)NewHandle(sizeof(PrefsStruct));
  500.         if (!prefs) 
  501.             DebugStr ("\pCouldnt get memory for prefs data.");
  502.         (**prefs).MakeInvis = false;
  503.         (**prefs).PutAway  = true;
  504.         (**prefs).MoveToFolder = false;
  505.         (**prefs).MakeInvisWNF = true;
  506.         BlockMove (kDefaultFolderName,(**prefs).folderName,LENGTH(kDefaultFolderName)+1);
  507.         AddResource ((Handle)prefs,kPrefsType,kPrefsID,"\p");
  508.     }
  509.     DetachResource ((Handle)prefs);
  510.     CloseResFile (rnum);
  511. }
  512.  
  513. void SavePrefs ()
  514. {
  515.     short vref,rnum;
  516.     long dirid;
  517.     FSSpec prefsFile;
  518.     OSErr err;
  519.     Handle h;
  520.     
  521.     FindFolder(kOnSystemDisk,kPreferencesFolderType,true,&vref,&dirid);
  522.     err = FSMakeFSSpec (vref,dirid,"\pDesktopSwitch Prefs",&prefsFile);
  523.     if (err) {
  524.         FSpCreateResFile (&prefsFile,'DTSW','dspr',0);
  525.     }
  526.     rnum = FSpOpenResFile (&prefsFile,fsRdWrPerm);
  527.     h = Get1Resource(kPrefsType,kPrefsID);
  528.     if (h) {
  529.         RmveResource (h);
  530.         DisposHandle (h);
  531.     }
  532.     AddResource ((Handle)prefs,kPrefsType,kPrefsID,"\p");
  533.     DetachResource ((Handle)prefs);
  534.     CloseResFile (rnum);
  535. }
  536.  
  537. void AskUserForDTFile() {
  538.     SFTypeList types;
  539.     StandardFileReply reply;
  540.     
  541.     types[0] = 'dset';
  542.     StandardGetFile (NULL,1,types,&reply);
  543.     if (reply.sfGood) {
  544.         LoadDesktopFile(reply.sfFile);
  545.     }
  546. }
  547.  
  548. main()
  549. {
  550.     short numFiles;
  551.     short whatToDo;
  552.     FSSpec spec;
  553.     
  554.     InitProg();
  555. /*    CountAppFiles (&whatToDo,&numFiles);
  556.     if (numFiles && !whatToDo) {
  557.         AppFile theFile;
  558.         
  559.         GetAppFiles (1,&theFile);
  560.         FSMakeFSSpec (theFile.vRefNum,0,theFile.fName,&spec);
  561.         LoadDesktopFile (spec);
  562.         ExitToShell();
  563.     } */
  564.     mel();
  565. }
  566.